package com.leetcode.binary_search;

/**
 * @author Dennis Li
 * @date 2020/11/4 20:28
 */
public class FindMin_154 {

    public int findMin(int[] nums) {
        int i = 0, j = nums.length - 1;
        while (i < j) {
            int mid = i + (j - i) / 2;
            if (nums[mid] < nums[j]) {
                // 保留j作为最小值
                j = mid;
            } else if (nums[mid] > nums[j]) {
                // i逐渐向右端逼近
                i = mid + 1;
            } else if (nums[mid] == nums[j]) {
                // 当mid和右边界值相等，选择缩小右边界
                j--;
            }
        }
        return nums[i];
    }

}
